<!DOCTYPE html>
<html>
  <head>
    <style>
    body {
      font-size: 30px;
    }
    </style>
  </head>
  <body>
    <div></div>

    <script>
function Matrix(ary) {
    this.mtx = ary
    this.height = ary.length;
    this.width = ary[0].length;
}

Matrix.prototype.toString = function() {
    var s = []
    for (var i = 0; i < this.mtx.length; i++)
        s.push( this.mtx[i].join(",") );
    return s.join("\n");
}

Matrix.prototype.mult = function(other) {
    if (this.width != other.height) {
        throw "error: incompatible sizes";
    }

    var result = [];
    for (var i = 0; i < this.height; i++) {
        result[i] = [];
        for (var j = 0; j < other.width; j++) {
            var sum = 0;
            for (var k = 0; k < this.width; k++) {
                sum += this.mtx[i][k] * other.mtx[k][j];
            }
            result[i][j] = sum;
        }
    }
    return new Matrix(result);
}

function run() {
  var elems = [];
  for (var i = 0; i < 900; i++) {
    elems.push(i);
  }
  var outer = [];
  for (var i = 0; i < 900; i++) {
    outer.push(elems);
  }
  var a = new Matrix(outer);
  var b = new Matrix(outer);
  var result = a.mult(b);
}

function say(msg) {
  var div = document.getElementsByTagName('div')[0];
  var text = document.createTextNode(msg);
  var p = document.createElement("p");
  p.appendChild(text);
  div.appendChild(p);
}

//say("multiplying 900x900 matrix");
setTimeout(function forever() {
  var now = new Date();
  run();
  say("mult 900x900 in " + (new Date() - now));
  setTimeout(forever, 5000);
}, 1000);
    </script>
  </body>
</html>
